package com.cyl.manager.oms.controller;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.cyl.manager.oms.convert.OrderItemPrepareConvert;
import com.cyl.manager.oms.domain.entity.OrderItemPrepare;
import com.cyl.manager.oms.domain.form.OrderItemPrepareFrom;
import com.cyl.manager.oms.domain.query.OrderItemPrepareQuery;
import com.cyl.manager.oms.domain.vo.OrderItemPrepareExcelVO;
import com.cyl.manager.oms.domain.vo.OrderItemPrepareVO;
import com.cyl.manager.oms.service.OrderItemPrepareService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
/**
 * 备货管理Controller
 *
 * @author zcc
 * @date 2025-02-11
 */
@Api(description ="备货管理接口列表")
@RestController
@RequestMapping("/oms/orderItemPrepare")
public class OrderItemPrepareController extends BaseController {
    @Autowired
    private OrderItemPrepareService service;
    @Autowired
    private OrderItemPrepareConvert convert;

    @ApiOperation("查询备货管理列表")
    @PreAuthorize("@ss.hasPermi('oms:orderItemPrepare:list')")
    @PostMapping("/list")
    public ResponseEntity<Page<OrderItemPrepareExcelVO>> list(@RequestBody OrderItemPrepareQuery query, Pageable page) {
    	Long qrDeptZbjId = SecurityUtils.getDeptZbjId();
        if(qrDeptZbjId!=null) {
        	query.setDeptZbjId(qrDeptZbjId);
        }
    	Map<String, Object> map = service.selectListByExcel(query, page);
        List<OrderItemPrepareExcelVO> list = (List<OrderItemPrepareExcelVO>) map.get("list");
        return ResponseEntity.ok(new PageImpl<OrderItemPrepareExcelVO>(list, page, (long)map.get("count")));
    }

    @ApiOperation("导出备货管理列表")
    @PreAuthorize("@ss.hasPermi('oms:orderItemPrepare:export')")
    @Log(title = "备货管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public ResponseEntity<String> export(OrderItemPrepareQuery query) {
    	query.setDeptZbjId(SecurityUtils.getDeptZbjId());
    	Map<String, Object> map = service.selectListByExcel(query, null);
        List<OrderItemPrepareExcelVO> list = (List<OrderItemPrepareExcelVO>) map.get("list");
        ExcelUtil<OrderItemPrepareExcelVO> util = new ExcelUtil<>(OrderItemPrepareExcelVO.class);
        return ResponseEntity.ok(util.writeExcel(list, "备货管理数据"));
    }

    @ApiOperation("获取备货管理详细信息")
    @PreAuthorize("@ss.hasPermi('oms:orderItemPrepare:query')")
    @GetMapping(value = "/{id}")
    public ResponseEntity<OrderItemPrepare> getInfo(@PathVariable("id") Long id) {
        return ResponseEntity.ok(service.selectById(id));
    }

//    @ApiOperation("新增备货管理")
//    @PreAuthorize("@ss.hasPermi('oms:orderItemPrepare:add')")
//    @Log(title = "备货管理", businessType = BusinessType.INSERT)
//    @PostMapping
//    public ResponseEntity<Integer> add(@RequestBody OrderItemPrepare orderItemPrepare) {
//        return ResponseEntity.ok(service.insert(orderItemPrepare));
//    }

    @ApiOperation("修改备货管理")
    @PreAuthorize("@ss.hasPermi('oms:orderItemPrepare:edit')")
    @Log(title = "备货管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResponseEntity<Integer> edit(@RequestBody OrderItemPrepareFrom orderItemPrepare) {
    	orderItemPrepare.setUpdateTime(LocalDateTime.now());
    	orderItemPrepare.setUpdateBy(SecurityUtils.getUserId());
        return ResponseEntity.ok(service.updateBhZt(orderItemPrepare));
    }
    
//    
//    @ApiOperation("修改备货状态")
//    @PreAuthorize("@ss.hasPermi('oms:orderItemPrepare:updateBhZt')")
//    @Log(title = "修改备货状态", businessType = BusinessType.UPDATE)
//    @PutMapping("/updateBhZt")
//    public ResponseEntity<Integer> updateBhZt(@RequestBody OrderItemPrepare orderItemPrepare) {
//        return ResponseEntity.ok(service.updateBhZt(orderItemPrepare));//这里可能有问题
//    }
    
    

//    @ApiOperation("删除备货管理")
//    @PreAuthorize("@ss.hasPermi('oms:orderItemPrepare:remove')")
//    @Log(title = "备货管理", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public ResponseEntity<Integer> remove(@PathVariable Long[] ids) {
//        return ResponseEntity.ok(service.deleteByIds(ids));
//    }
}
